package com.tengju.bff.interfaces.covercharge.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.tengju.user.domain.model.archive.sign.SignFromEnum;
import com.tengju.bff.interfaces.covercharge.entity.po.ServiceSignRecord;
import com.tengju.bff.interfaces.covercharge.entity.vo.ServiceSignRecordVo;
import com.tengju.bff.interfaces.covercharge.mapper.ServiceSignRecordMapper;
import com.tengju.bff.interfaces.covercharge.service.IServiceSignRecordService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 服务费经销商签约表 服务实现类
 * </p>
 *
 * @author fwy
 * @since 2020-03-04
 */
@Service
@Slf4j
public class ServiceSignRecordServiceImpl extends ServiceImpl<ServiceSignRecordMapper, ServiceSignRecord> implements IServiceSignRecordService {
    /**
     * 获取单条信息
     * @param signId
     * @param signFrom
     * @return
     */
    @Override
    public ServiceSignRecordVo queryFirst(Integer signId, Integer signFrom){
        return this.baseMapper.queryFirst(signId,signFrom);
    }

    /**
     * 更新为失效
     * @param signId
     * @param signFrom
     * @return
     */
    @Override
    public void updateStatus(Integer signId, Integer signFrom){
        this.baseMapper.updateStatus(signId,signFrom);
    }

    /**
     * 获取DT区域服务商最后一条签约记录信息
     * @param signId
     * @return
     */
    @Override
    public ServiceSignRecord queryByLastInfo(Integer signId){
        QueryWrapper<ServiceSignRecord> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("sign_id", signId);
        queryWrapper.eq("sign_from", SignFromEnum.SERVICE_PROVIDER.getCode());
        queryWrapper.orderByDesc("id");
        queryWrapper.last("limit 1");
        return this.baseMapper.selectOne(queryWrapper);
    }
}
